﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using BUS;
using DTO;
namespace PTTK11_HuongRung
{
    public partial class frmQuanLy : Form
    {
        public frmQuanLy()
        {
            InitializeComponent();

            Timer tmr = new Timer();
            tmr.Tick += new EventHandler(timer_Tick);
            tmr.Start();
        }
        void loadEnd()
        {
            btnBanVe.Enabled=false;
            btnDatHang.Enabled = false;
            btnLapPhieuYC.Enabled = false;
            btnLichLamViec.Enabled = false; 
            btnMonAN.Enabled = false;
            btnNhapKho.Enabled = false;
            btnThucDon.Enabled = false;
            btnXuatKho.Enabled = false; 

        }
        void QuanLy()
        {
            btnBanVe.Enabled = false;
            btnDatHang.Enabled = false;
            btnLapPhieuYC.Enabled = true;
            btnLichLamViec.Enabled = true;
            btnMonAN.Enabled = true;
            btnNhapKho.Enabled = false;
            btnThucDon.Enabled = true;
            btnXuatKho.Enabled = false; 
        }
        void ThuNgan()
        {
            btnBanVe.Enabled = true;
            btnDatHang.Enabled = false;
            btnLapPhieuYC.Enabled = false;
            btnLichLamViec.Enabled = false;
            btnMonAN.Enabled = false;
            btnNhapKho.Enabled = false;
            btnThucDon.Enabled = false;
            btnXuatKho.Enabled = false; 
        }
        void BepTruong()
        {
            btnBanVe.Enabled = false;
            btnDatHang.Enabled = false;
            btnLapPhieuYC.Enabled = true;
            btnLichLamViec.Enabled = false;
            btnMonAN.Enabled = false;
            btnNhapKho.Enabled = false;
            btnThucDon.Enabled = false;
            btnXuatKho.Enabled = false; 
        }
        void ThuKho()
        {
            btnBanVe.Enabled = false;
            btnDatHang.Enabled = false;
            btnLapPhieuYC.Enabled = false;
            btnLichLamViec.Enabled = false;
            btnMonAN.Enabled = false;
            btnNhapKho.Enabled = true;
            btnThucDon.Enabled = false;
            btnXuatKho.Enabled = true; 
        }
        void ThuMua()
        {
            btnBanVe.Enabled = false;
            btnDatHang.Enabled = true;
            btnLapPhieuYC.Enabled = false;
            btnLichLamViec.Enabled = false;
            btnMonAN.Enabled = false;
            btnNhapKho.Enabled = false;
            btnThucDon.Enabled = false;
            btnXuatKho.Enabled = false; 
        }
        void Admin()
        {
            btnBanVe.Enabled = true;
            btnDatHang.Enabled = true;
            btnLapPhieuYC.Enabled = true;
            btnLichLamViec.Enabled = true;
            btnMonAN.Enabled = true;
            btnNhapKho.Enabled = true;
            btnThucDon.Enabled = true;
            btnXuatKho.Enabled = true; 
        }

        private void frmQuanLy_Load(object sender, EventArgs e)
        {
            loadEnd();
            if (Secssion.MaNV.Count() <= 0)
            {
                btnDangNhap.Text = "Đăng Nhâp";
                txtMaNV.Text = "";
                txtHoTen.Text = "";
                return;
            }
            else
            {
                btnDangNhap.Text = "Đăng Xuất";
                NhanVienBUS nvBus = new NhanVienBUS();
                NhanVienDTO nvDto = new NhanVienDTO();
                nvDto = nvBus.GetThongTinNhanVien(Secssion.MaNV);
                txtHoTen.Text = nvDto.TENNHANVIEN.Trim();
                LoaiNhanVienBUS lnvbus = new LoaiNhanVienBUS();                   
                txtMaNV.Text = lnvbus.GetTenLoaiNV(nvDto.LOAINHANVIEN);
                if (nvDto.LOAINHANVIEN == 1)
                    Admin();
                else if (nvDto.LOAINHANVIEN == 2)
                    QuanLy();
                else if (nvDto.LOAINHANVIEN == 3)
                    ThuNgan();
                else if (nvDto.LOAINHANVIEN == 4)
                    BepTruong();
                else if (nvDto.LOAINHANVIEN == 5)
                    ThuKho();
                else if (nvDto.LOAINHANVIEN == 6)
                    ThuMua();

                    
            }
        }

        private void btnThucDon_Click(object sender, EventArgs e)
        {
            this.Hide();
            frmThucDon frm = new frmThucDon();
            frm.ShowDialog();
            this.Close();
        }

        private void btnMonAN_Click(object sender, EventArgs e)
        {
            this.Hide();

            frmMonAn frm = new frmMonAn();
            frm.ShowDialog();
            this.Close();
        }


        private void timer_Tick(object sender, EventArgs e)
        {
            ThoiGian.Text = DateTime.Now.ToString("dd/MM/yyyy HH:mm:ss");
        }

        private void btnBanVe_Click(object sender, EventArgs e)
        {
            this.Hide();

            frmBanVe frm = new frmBanVe();
            frm.ShowDialog();
            this.Close();
        }

        private void btnDatHang_Click(object sender, EventArgs e)
        {
            this.Hide();

            frmDatHang frm = new frmDatHang();
            frm.ShowDialog();
            this.Close();
        }

        private void btnNhapKho_Click(object sender, EventArgs e)
        {
            this.Hide();

            frmNhapKho frm = new frmNhapKho();
            frm.ShowDialog();
            this.Close();
        }

        private void btnXuatKho_Click(object sender, EventArgs e)
        {
            this.Hide();

            frmXuatKho frm = new frmXuatKho();
            frm.ShowDialog();
            this.Close();
        }

        private void frmQuanLy_FormClosing(object sender, FormClosingEventArgs e)
        {
            Application.Exit();
        }

        private void btnDangNhap_Click(object sender, EventArgs e)
        {
            if (btnDangNhap.Text.Trim().CompareTo("Đăng Xuất") ==0 )
            {
                btnDangNhap.Text="Đăng Nhâp";
                Secssion.MaNV = "";
                Secssion.MaKhac = "";
                loadEnd();
                txtHoTen.Text = "";
                txtMaNV.Text = "";
            }
            else
            {
                this.Hide();
                frmDangNhap frm = new frmDangNhap();
                frm.ShowDialog();
                this.Close();
            }
        }
    }
}
